require(['./config'], () => {
require(['swiper', 'template', 'header', 'footer', 'utils'], (Swiper, template) => {
   class Index {
	   constructor() {
	       this.register()
	   }
		register(){
			var sub = document.querySelector('#sub')
			var nameInput = document.querySelector('#name')
			var pwdInput = document.querySelector('#pwd')
			//console.log(nameInput)
			sub.onclick = function () {
			  const name = nameInput.value
			  const pwd = pwdInput.value
			  console.log(name)
			  // 带上用户名和密码向后端发送请求
			  // { name: name, pwd: pwd } 在ES6里可以简写为{ name, pwd }
			  utils.post('http://localhost/2stage/2exsesize/day25exsesize/el-shop/api/user/register.php', { name, pwd }, resp => {
			    if (resp.code === 200) {
					console.log(resp)
			      alert(resp.body.msg + '，即将跳转登录页')
			      location.href = '/html/login.html'
			    } else {
			      // 注册失败
			      alert(resp.body.msg)
			    }
			  })
			  return false
			}
		}
    }
   new Index()
 
   })
})